package cn.hbads.support.log;

import org.slf4j.event.Level;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>日志后处理器组合器</b>
 *
 * @author yvvb
 * @date 2025/5/4
 */
@Component
public class LogPostHandlerComposite implements LogPostHandler {

    private final List<LogPostHandler> logPostHandlerList;

    public LogPostHandlerComposite(List<LogPostHandler> logPostHandlerList) {
        if (CollectionUtils.isEmpty(logPostHandlerList)) {
            this.logPostHandlerList = new ArrayList<>();
        } else {
            this.logPostHandlerList = logPostHandlerList;
        }
    }

    @Override
    public void handlerLog(String logStr, Level logLevel) {
        logPostHandlerList.forEach(handler -> handlerLog(logStr, logLevel));
    }
}
